package org.abettor.angleworm.ui;

import java.io.IOException;

import org.abettor.angleworm.i18n.Translator;
import org.abettor.util.Environment;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;

public class LoginOptionDialog
{
	private static Translator translator = null;
	private static final int WIDTH = 304;
	private static final int HEIGHT = 300;
	private Display display = Display.getDefault();
	private Shell optionShell = null;

	/**
	 * 显示主窗口
	 */
	public void show()
	{
		//TODO	显示登录选项窗口
		if("a".equals("a"))
		{
			return;
		}
		createOptionShell();
		optionShell.open();
		while(! optionShell.isDisposed())
		{
			if(! display.readAndDispatch())
			{
				display.sleep();
			}
		}
	}

	/**
	 * 绘制主窗口
	 */
	private void createOptionShell()
	{
		try
		{
			translator = Translator.getInstance();
			if(translator == null)
			{
				translator = Translator.initialize("en_US");
			}
		}
		catch (IOException e)
		{
			e.printStackTrace();
			return;
		}

		Monitor monitor = display.getPrimaryMonitor();
        Rectangle rect = monitor.getBounds();
		optionShell = new Shell(SWT.CLOSE | SWT.SYSTEM_MODAL);
		optionShell.setText(translator.getString("login.option.dialog.title"));
		optionShell.setImage(new Image(display, Environment.getFilePath("img/logo.png")));
		optionShell.setSize(new Point(WIDTH, HEIGHT));
		optionShell.setLocation((rect.width - WIDTH) / 2, (rect.height - HEIGHT) / 2);
		optionShell.setLayout(new GridLayout());
	}
}
